package com.zt.english.activity

import com.zt.english.bean.TextTranslateBean
import com.zt.english.network.TranslateRetrofits
import com.zt.english.network.api.TranslateAPI
import com.zt.mvvm.repository.BaseRepository
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn

class TranslateRepository:BaseRepository {
    private val translateAPI = TranslateRetrofits.create().authorizedService().create(TranslateAPI::class.java)

    /**
     * 有道文本翻译
     */
    fun translateTxt(params:HashMap<String,String>):Flow<TextTranslateBean>{
        return flow<TextTranslateBean>{
            val data = translateAPI.transleteText(params)
            emit(data)
        }.flowOn(Dispatchers.IO)
    }
}